﻿// import tools from "../tools";
// const { typeOf } = tools;

// ﻿export * from '../tools'
// import { typeOf } from "../tools";

const tools = require('../tools');
const { typeOf } = tools;
// console.log('module',module);

const _tips2 = function(title,url,reqdata,isTrue){
    return new Promise((resolve, reject) => {
        let _this = this;
        let obj = {
            title: '提示',
            content: title,
            onOk(){
                resolve();
            }
        };
        if(url){
            obj = {
                title: title,
                loading: true,
                content: '确认要操作吗',
                async onOk(){
                    let res = await _this.$post(url,reqdata||{});
                    this.buttonLoading = false;
                    if(res) {
                        if(typeOf(isTrue)=='function'){
                            if(isTrue(res)){
                                _this.$Modal.remove();
                                _this.$tipsMessage('操作成功',1);
                                resolve();
                            }else{
                                _this.$tipsMessage('操作失败');
                                reject();
                            }
                            return false;
                        };
                        //默认处理
                        _this.$Modal.remove();
                        if(_this.selectList) _this.selectList = [];
                        if(_this.GetList) _this.GetList();
                        resolve();
                    };
                }
            }
        }
        return _this.$Modal.confirm(obj);
    });
};

const _sortIndex = function(res,sort,resIndex=0){
    if(res[resIndex] && res[resIndex].sort && res[resIndex].sort>=sort) return _sortIndex(res,sort,resIndex+1);
    return resIndex;
};

const _refresh = function(data){
    // console.log('_refresh',this.$options.name,data,this.pages);
    if(this.pages && this.pages.includes(data)){ //childPage
        console.log('刷新');
        return this.GetList();
    };
};

const go_list = function(){
    if(!this.isDetail) this.bus.$emit('refresh',this.$options.name);
    this.closeNoTag({
        name: this.$options.name,
        params: { id: this.pageId }
    });
    this.$go({name:this.$route.meta.specialCode,replace:true}, this.$router,1);
};

//js - 对象绑定
const defineP_formatObj = function(o){
    if(o && typeof o === 'object') return o;
    else {
        return {
            get(){
                return o;
            }
        }
    };
};
const definePros_formatObj = function(obj){
    let res = {};
    for(let key in obj){
        res[key] = defineP_formatObj(obj[key]);
    };
    return res;
};
const definePros= function(source,params,aloneKey){
    if(aloneKey){
        return Object.defineProperty(source,aloneKey,defineP_formatObj(params));
    }else{
        if(!params || typeof params !== 'object') return source;
        return Object.defineProperties(source,definePros_formatObj(params));
    };
};
module.exports = {
    ...tools,
    _tips2,
    _sortIndex,
    _refresh,
    go_list,
    definePros,
}
// ﻿export {